package win.bigwhale.sudoku.logic;

import java.util.ArrayList;

import win.bigwhale.sudoku.SudokuUtil;

public class NumberGroup {
	private ArrayList<SudokuNumber> nineNumber = null;
	
	public NumberGroup() {
		nineNumber = new ArrayList<SudokuNumber>();
	}

	public void add(SudokuNumber number) {
		nineNumber.add(number);
	}

	/*
	 * if number is valid, return true.
	 * Otherwise, return false.
	 */
	public boolean isValid(SudokuNumber number) {
		if (nineNumber.size() >= 9) {
			return false;
		}
		for (SudokuNumber sudokuNumber : nineNumber) {
			if (sudokuNumber.getNumber() == number.getNumber()) {
				return false;
			}
		}
		return true;
	}

	public void removeNumber(SudokuNumber number) {
		if (nineNumber.contains(number)) {
			nineNumber.remove(number);
		}
	}

	public void setFinishedColor() {
		if (isFull()) {
			for (SudokuNumber sudokuNumber : nineNumber) {
				sudokuNumber.getNumText().setFill(SudokuUtil.HUAQIANCONG_COLOR);
			}
		}
	}

	private boolean isFull() {
		if (nineNumber.size() == 9) {
			return true;
		}
		return false;
	}

	public void setBackColor() {
		for (SudokuNumber sudokuNumber : nineNumber) {
			if (sudokuNumber.isOrig()) {
				sudokuNumber.getNumText().setFill(SudokuUtil.JIAOCHA_COLOR);
			} else {
				sudokuNumber.getNumText().setFill(SudokuUtil.CHANGPAN_COLOR);
			}
		}
	}
}
